# Build recipe for graft.
#
# Copyright (c) 2017-2018 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=graft
version=2.16
arch=noarch
release=1

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=http://peters.gormand.com.au/Home/tools/graft/$tarname

description="
A package management utility.

Graft provides a mechanism for managing multiple packages under a single
directory hierarchy. Packages are installed in self contained directory
trees and symbolic links from a common area are made to the package files.

This approach allows multiple versions of the same package to co-exist on
the one system. One version is the commonly available version and symbolic
links will be made to this version. New versions can be tested and once
acceptable can replace the current commonly available version. Older
versions can still be used for legacy systems by using the 'real' path
name to the package instead of the 'common' path name.
"

homepage=http://peters.gormand.com.au/Home/tools/graft
license=GPLv2+

# Source documentation
docs="CHANGES COPYING README THOUGHTS doc/graft.html doc/graft.pdf doc/graft.txt"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    cp -f Makefile.dist Makefile

    make \
     PACKAGEDIR=/usr/pkg       \
     TARGETDIR=/               \
     BIN="${destdir}/usr/bin"  \
     MAN="${destdir}/$mandir"  \
     DOC="${destdir}/$docsdir" \
     install

    # Compress manual page
    lzip -9 "${destdir}/${mandir}/man1/graft.1"

    # Copy source documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"

    # Remove shipped .nograft from DOC
    rm -f "${destdir}${docsdir}/.nograft"

#    # Exclude graft to being grafted by graft(1) for safe updates
#    echo graft > "${destdir}/usr/bin/.graft-exclude"
#
#    # Insert post-install script manually
#
#    mkdir -p "${destdir}/var/lib/qi"
#    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"
#
## Copy graft from 'targetdir' taking 'packagedir' into account
#mkdir -p -- usr/bin
#cp -f -p "\$rootdir\${packagedir}/\${name}/usr/bin/graft" usr/bin/
#
#EOF
}

